package com.lrd.snapshotorder.repository;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lrd.snapshotorder.entity.RecipientAddress;
import com.lrd.snapshotorder.mapper.RecipientAddressMapper;
import com.lrd.snapshotorder.protocol.dto.address.RecipientAddressQueryDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

@Repository
public class RecipientAddressRepository {

    @Autowired
    private RecipientAddressMapper recipientAddressMapper;

    public List<RecipientAddress> getAll(RecipientAddressQueryDto dto) {
        List<RecipientAddress> all = new ArrayList<>();
        //Integer total = recipientAddressMapper.getTotal(dto);
        Page<RecipientAddress> recipientAddressPage = recipientAddressMapper.queryRecipientAddressList(dto);
        if (CollUtil.isEmpty(recipientAddressPage.getRecords())) {
            return all;
        } else {
            int recordSize = recipientAddressPage.getRecords().size();
            if (recordSize < dto.getPageSize()) {
                dto.setPageSize(recordSize);
            }
        }
        return null;
    }
}
